package com.koicarp.university.graduate.web.controller;

import com.koicarp.university.graduate.service.service.menu.ISysMenuService;
import com.koicarp.university.graudate.common.constant.BaseConstant;
import com.koicarp.university.graudate.common.entity.SysMenu;
import com.koicarp.university.graudate.common.utils.UniversityResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 【用户管理：菜单表】(SysMenu)表控制层
 *
 * @author liutao
 * @since 2020-09-03 19:53:52
 */
@RestController
@RequestMapping("sysMenu")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "菜单表控制层")
public class SysMenuController {
    /**
     * 服务对象
     */
    private final ISysMenuService sysMenuService;

    @PostMapping("getMenuByTree")
    @ApiOperation(value = "树形结构角色",notes = "树形结构角色")
    public UniversityResponse getMenuByTree(){
        UniversityResponse response=null;
        try{
            response = sysMenuService.getMenuByTree();
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public SysMenu selectOne(Long id) {
        return this.sysMenuService.queryById(id);
    }

}